//
//  HMReputationDoctor.m
//  仿真开发
//
//  Created by B.HOPE on 2017/3/23.
//  Copyright © 2017年 B.HOPE. All rights reserved.
//

#import "HMReputationDoctor.h"
#import "HMTool.h"
#import "HMReputationDoctorCell.h"
#import "HMReputationDoctoModel.h"
#import <YYModel.h>
#import "MJRefresh.h"
#import "AppointDoctorView.h"
#import "HMDocDeatilView.h"
#import "HMReputationDoctoModel.h"


@interface HMReputationDoctor ()

@property (nonatomic, strong) NSArray *arrayModel;

@property (nonatomic,strong) MJRefreshNormalHeader *header;

@property (nonatomic,strong) MJRefreshAutoNormalFooter *footer;

@property (nonatomic,strong) HMReputationDoctoModel *reputatModel;

@end

static NSString *doctor = @"doctor";

@implementation HMReputationDoctor

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _arrayModel = [[NSArray alloc] init];
    [self loadData];
    
    [self.tableView registerClass:[HMReputationDoctorCell class] forCellReuseIdentifier:doctor];
    
    self.tableView.rowHeight = 100;
    
    _header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    _footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadData)];
    
    self.tableView.mj_header = _header;
    self.tableView.mj_footer = _footer;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arrayModel.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HMReputationDoctorCell *cell = [tableView dequeueReusableCellWithIdentifier:doctor forIndexPath:indexPath];
    
    cell.model = _arrayModel[indexPath.row];
    
    
    
    return cell;
}

- (void)loadData
{
    NSString *strURL = @"http://iosapi.itcast.cn/doctor/matchDoctors.json.php";
    NSDictionary *dict = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"page_size":@15,@"is_confirmed":@1,@"user_id":@1000089, @"page":@1,@"has_diagnosis":@2};
    
    [[HMTool sharedNetworkTool] POSTWithURLString:strURL parameters:dict success:^(id responseObject)
     {
         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
         NSArray *array = dict[@"data"];
         
         _arrayModel = [NSArray yy_modelArrayWithClass:[HMReputationDoctoModel class] json:array];
         
         [_header endRefreshing];
         [_footer endRefreshing];
         [self.tableView reloadData];
     }
                                            faile:^(NSError *error)
     {
         NSLog(@"%@",error);
     }];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AppointDoctorView" bundle:nil];
    
    
    AppointDoctorView *deatilVc = [sb instantiateInitialViewController];
   
    // 顺传 得到 相对应的解析的model
    HMReputationDoctoModel *model = _arrayModel[indexPath.row];
    
    // 在控制器定义一个相对应的模型属性接收
    deatilVc.reModel = model;
    
    [self.navigationController pushViewController:deatilVc animated:YES];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    
}

@end
